﻿
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;

using System.IO;
using System.Collections.Generic;

using System.Data.SqlClient;
using System.Web.Services;

using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Configuration;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

using System.Web.Services;
public partial class admin_view_for_rent : System.Web.UI.Page
{
    string ss;
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["p_id"] = Request.QueryString["id"].ToString();
        BindGridviewData();
        Label67.Text = Session["p_id"].ToString();

        if (Session["email"] == null)
        {
            Session["email"] = "admin";
        }
        ss = Session["p_id"].ToString();
        Label1.Text = Session["email"].ToString();

        if (Label16.Text=="0")
        {
            Label16.Visible= false;
        }

        if (Page.IsPostBack)
        {
        }
        else
        {
            string str = Session["p_id"].ToString();
           // Image1.ImageUrl = Server.MapPath("upload/" + Session["p_id"] + "/" + "Image/");

            //string[] files = Directory.GetFiles("Location of Files", "*.jpg");

            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);


            conn.Open();
            SqlCommand scmd = new SqlCommand("SELECT * FROM properties_rent where p_id='" + Session["p_id"] + "'", conn);

            SqlDataReader dr = scmd.ExecuteReader();
            if (dr.Read())
            {
                txtclient_fullname2.Text = dr[8].ToString();
                lblphone.Text = dr[10].ToString();
                lblhouse.Text = dr[12].ToString();
                lblneigh.Text = dr[13].ToString();
                lblcount.Text = dr[15].ToString();
                lblzip.Text = dr[16].ToString();
                lblptype.Text = dr[17].ToString();
                lblptype1.Text = dr[18].ToString();
                lblpcondi.Text = dr[19].ToString();
                lblpcondi1.Text = dr[20].ToString();
                lblstr.Text = dr[25].ToString();
                lblhs.Text = dr[26].ToString();
                lblap.Text = dr[27].ToString();
                Label2.Text = dr[28].ToString();
                Label3.Text = dr[29].ToString();
                Label4.Text = dr[30].ToString();
                Label5.Text = dr[31].ToString();
                Label8.Text = dr[32].ToString();
                Label6.Text = dr[35].ToString();
                Label7.Text = dr[36].ToString();
                Label9.Text = dr[37].ToString();
                Label10.Text = dr[38].ToString();
                Label11.Text = dr[39].ToString();
                Label12.Text = dr[40].ToString();
                Label13.Text = dr[41].ToString();
                Label14.Text = dr[42].ToString();
                Label15.Text = dr[43].ToString();
                Label16.Text = dr[44].ToString();
                Label17.Text = dr[45].ToString();
                Label18.Text = dr[46].ToString();
                Label19.Text = dr[49].ToString();
                Label20.Text = dr[50].ToString();
                Label21.Text = dr[51].ToString();
                Label22.Text = dr[52].ToString();
                Label23.Text = dr[53].ToString();
                Label24.Text = dr[54].ToString();
                Label25.Text = dr[55].ToString();
                Label26.Text = dr[56].ToString();
                Label27.Text = dr[57].ToString();
                Label28.Text = dr[62].ToString();
                Label29.Text = dr[63].ToString();
                Label30.Text = dr[64].ToString();
                Label31.Text = dr[65].ToString();
                Label32.Text = dr[66].ToString();
                Label33.Text = dr[67].ToString();
                Label34.Text = dr[68].ToString();
                Label35.Text = dr[69].ToString();
                Label36.Text = dr[70].ToString();
                Label37.Text = dr[71].ToString();
                Label38.Text = dr[72].ToString();
                Label39.Text = dr[73].ToString();
                Label40.Text = dr[74].ToString();
                Label41.Text = dr[75].ToString();
                Label42.Text = dr[76].ToString();
                Label43.Text = dr[79].ToString();
                Label44.Text = dr[80].ToString();
                Label45.Text = dr[81].ToString();
                Label46.Text = dr[82].ToString();
                Label47.Text = dr[83].ToString();
                Label48.Text = dr[84].ToString();
                Label49.Text = dr[85].ToString();
                Label50.Text = dr[86].ToString();
                Label51.Text = dr[87].ToString();
                Label52.Text = dr[89].ToString();
                Label53.Text = dr[90].ToString();
                Label54.Text = dr[92].ToString();
                Label55.Text = dr[93].ToString();
                Label56.Text = dr[94].ToString();
                Label57.Text = dr[95].ToString();
                Label58.Text = dr[96].ToString();
                Label59.Text = dr[97].ToString();
                Label60.Text = dr[98].ToString();
                Label61.Text = dr[99].ToString();
                Label62.Text = dr[100].ToString();
                Label63.Text = dr[101].ToString();
                Label64.Text = dr[123].ToString();
                Label65.Text = dr[102].ToString();
                Label66.Text = dr[103].ToString();



                lblsteet.Text = dr[11].ToString();
                
                

                //   txtfname1.Text = dr[1].ToString();
                txtclient_fullname1.Text = dr[7].ToString();
              
                
                // lblname.Text=dr[6].ToString ();
                Lblpermises.Text=dr[118].ToString ();
                lblssn.Text = dr[9].ToString();
                lblcity.Text = dr[14].ToString();
                lblclient.Text = dr[2].ToString();

                lbltype.Text = "To Rent";
            }

            
            dr.Close();


         
            //SqlCommand scmd1 = new SqlCommand("SELECT * FROM task where p_id='" + Session["p_id"] + "'", conn);

            //SqlDataReader dr1 = scmd1.ExecuteReader();
            //if (dr1.Read())
            //{

            //    Label67.Text = dr1[1].ToString();
            //    Label68.Text = dr1[2].ToString();
            // }


            //dr1.Close();
        }


        
        ListImages();
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        

    }


         private void BindGridviewData()
         
    {
        SqlConnection con = null;
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);

        con.Open();
        SqlCommand cmd = new SqlCommand("select * from files where id='"+ Session["p_id"] +"'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        gvDetails.DataSource = ds;
        gvDetails.DataBind();

        con.Close();
    }
    protected void lnkDownload_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = sender as LinkButton;
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        string file_path = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        Response.ContentType = "image/jpg";
        Response.AddHeader("Content-Disposition", "attachment;filename=\"" + file_path + "\"");
        Response.TransmitFile(Server.MapPath(file_path));
        Response.End();
    }















    


private void ListImages()
{
    DirectoryInfo dir = new DirectoryInfo(Server.MapPath("upload/" + Session ["p_id"] +"/Image" ));
    FileInfo[] file = dir.GetFiles();
    ArrayList list = new ArrayList();
    foreach (FileInfo info in file)
    {
        if (info.Extension == ".jpg" || info.Extension == ".jpeg" || info.Extension == ".gif" || info.Extension == ".png")
        {
            list.Add(info);
        }


        FileRepeater.DataSource = list;
        FileRepeater.DataBind();
}




        //private void ListImages()
        //{

        //    DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/admin/upload/" + Session ["p_id"] +"/image" ));
        //    FileInfo[] file = dir.GetFiles();
        //    ArrayList list = new ArrayList();
        //    foreach (FileInfo file2 in file)
        //    {
        //        if (file2.Extension == ".jpg" || file2.Extension == ".jpeg" || file2.Extension == ".gif" || file2.Extension == ".png")
        //        {

        //            Image1.ImageUrl = Server .MapPath ("~/admin/upload/" + Session["p_id"] + "/image");
        //            list.Add(file2);
        //        }
        //    }
        //    DataList1.DataSource = list;
        //    DataList1.DataBind();
        //}

    }

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "view")
    {

        //Label1.Text = "hello";
        int index = Convert.ToSByte(e.CommandArgument);

        GridViewRow row = GridView2.Rows[index];
        SqlDataAdapter adp = new SqlDataAdapter();
        SqlCommand cmd1 = new SqlCommand();
        DataSet ds = new DataSet();


        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

        con.Open();

        SqlCommand objectvalue = new SqlCommand("", con);
        cmd1.Connection = con;



        SqlCommand dmc = new SqlCommand("select p_id from task where p_id='" + row.Cells[0].Text + "'", con);

        dmc.ExecuteNonQuery();
        Session["p_id"] = row.Cells[0].Text;

        con.Close();
        // Response.Write(Session["p_id"]);
        // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

        Response.Redirect("view-task.aspx");
        // con.Close();


    }




}
//protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
//{
//    if (e.CommandName == "action")
//    {

//        //Label1.Text = "hello";
//        int index = Convert.ToSByte(e.CommandArgument);

//        GridViewRow row = GridView3.Rows[index];
//        SqlDataAdapter adp = new SqlDataAdapter();
//        SqlCommand cmd1 = new SqlCommand();
//        DataSet ds = new DataSet();


//        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

//        con.Open();

//        SqlCommand objectvalue = new SqlCommand("", con);
//        cmd1.Connection = con;

//        SqlCommand dmc = new SqlCommand("Delete from task where p_id='" + row.Cells[2].Text + "'", con);
//        dmc.ExecuteNonQuery();

//        SqlCommand dmc1 = new SqlCommand("Delete from files where id='" + row.Cells[2].Text + "'", con);
//        dmc1.ExecuteNonQuery();

//        // SqlCommand dmc = new SqlCommand("select p_id from properties where p_id='" + row.Cells[0].Text + "'", con);

//        //dmc.ExecuteNonQuery();
//        //  Session["p_id"] = row.Cells[0].Text;

//        con.Close();
//        // Response.Write(Session["p_id"]);
//        // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

//        Response.Redirect("admin_notes.aspx");
//        // con.Close();


//    }

//    if (e.CommandName == "view")
//    {

//        //Label1.Text = "hello";
//        int index = Convert.ToSByte(e.CommandArgument);

//        GridViewRow row = GridView3.Rows[index];
//        SqlDataAdapter adp = new SqlDataAdapter();
//        SqlCommand cmd1 = new SqlCommand();
//        DataSet ds = new DataSet();


//        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

//        con.Open();

//        SqlCommand objectvalue = new SqlCommand("", con);
//        cmd1.Connection = con;



//        SqlCommand dmc = new SqlCommand("select p_id from task where p_id='" + row.Cells[0].Text + "'", con);

//        dmc.ExecuteNonQuery();
//        Session["p_id"] = row.Cells[0].Text;

//        con.Close();
//        // Response.Write(Session["p_id"]);
//        // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

//        Response.Redirect("doc.aspx");
//        // con.Close();


//    }




        protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }
        protected void Save_Click(object sender, EventArgs e)
        {

        }


    }
